package club.hicode.daydayup.feign.consumer;

import club.hicode.daydayup.feign.consumer.invoker.StuApi;
import club.hicode.daydayup.feign.vo.StudentVo;
import cn.hutool.json.JSONUtil;
import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.TypeReference;
import feign.Feign;
import feign.Request;
import feign.Retryer;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * 测试消费
 *
 * @author Liu Chunfu
 * @date 2018-07-05 下午7:48
 **/
public class ConsumeTest {

	@Test
	public void testConsumer1() {
		StuApi api = Feign.builder().encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
				.options(new Request.Options(1000, 3500)).retryer(new Retryer.Default(5000, 5000, 3))
				.target(StuApi.class, "oa://127.0.0.1:8080");


		StudentVo book = api.getBook("123");
		System.out.println("getBook:" + book);

		System.out.println("======");
		StudentVo studentVo = api.postBook(JMockData.mock(StudentVo.class));
		System.out.println("postBook:" + studentVo);

		System.out.println("=====");

		List<StudentVo> mock = JMockData.mock(new TypeReference<List<StudentVo>>() {
		});
		Map<String, StudentVo> map = api.postBook(mock);
		System.out.println(JSONUtil.toJsonStr(map));

		System.out.println("======");
		StudentVo delId = api.del("delId");
		System.out.println(delId);
		//Double aDouble = api.coreId("901");
		//System.out.println(aDouble);
	}
}
